import { useState } from 'react'
import { useDispatch } from 'react-redux'
import { addTodo } from '../store/todoSlice'
const InputItem = () => {

    const [value, setValue] = useState('1111')
    const dispatch = useDispatch()

    // 添加
    const add = () => {
        dispatch(addTodo(value))
        setValue('')
    }
    return (
        <div className="input-item d-flex">
            <input style={{ width: '80%' }} type="text" value={value} className="form-control" placeholder="请输入内容"
                onChange={(e) => setValue(e.target.value)} />
            <button style={{ marginLeft: '10px' }} className="btn btn-primary" onClick={add}>添加</button>
        </div>
    );
};

export default InputItem;